{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Problem definition"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2D EstimationProblem\n",
       "  data:      3×3 GeoDataFrame (x and y)\n",
       "  domain:    100×100 RegularGrid{Float64,2}\n",
       "  variables: variable (Float64)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "using GeoStats\n",
    "using DataFrames\n",
    "using Plots\n",
    "pyplot(size=(1000,500))\n",
    "\n",
    "df = DataFrame(x=[25.,50.,75.], y=[25.,75.,50.], variable=[1.,0.,1.])\n",
    "\n",
    "geodata = GeoDataFrame(df, [:x,:y])\n",
    "\n",
    "domain = RegularGrid{Float64}(100,100)\n",
    "\n",
    "problem = EstimationProblem(geodata, domain, :variable)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Solver options\n",
    "\n",
    "The user can specify the number of neighbors (default to all data locations) and a metric from the [Distances.jl](https://github.com/JuliaStats/Distances.jl) package (default to Euclidean). If the number of neighbors is set to 1, the algorithm reduces to a simple tesselation algorithm."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<img src=\"\" />"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "using InverseDistanceWeighting\n",
    "\n",
    "# default options\n",
    "solution = solve(problem, InvDistWeight())\n",
    "\n",
    "plot(solution)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<img src=\"\" />"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1 nearest neighbor => simple tesselation\n",
    "solver = InvDistWeight(\n",
    "    :variable => @NT(neighbors=1)\n",
    ")\n",
    "\n",
    "solution = solve(problem, solver)\n",
    "\n",
    "plot(solution)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<img src=\"\" />"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# custom metric\n",
    "solver = InvDistWeight(\n",
    "    :variable => @NT(distance=Chebyshev())\n",
    ")\n",
    "\n",
    "solution = solve(problem, solver)\n",
    "\n",
    "plot(solution)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Julia 0.6.2",
   "language": "julia",
   "name": "julia-0.6"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "0.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
